package com.ctshk.sapp.hotel.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.hotel.dto.*;
import com.ctshk.rpc.hotel.dto.booking.HotelBookingDetailsDTO;
import com.ctshk.rpc.hotel.dto.chimelongProxy.ChimeLongProxy;
import com.ctshk.rpc.hotel.dto.chimelongProxy.ProxyDatas;
import com.ctshk.rpc.hotel.req.*;
import com.ctshk.rpc.hotel.req.booking.HotelDetailsQueryReq;
import com.ctshk.rpc.hotel.service.IChimeLongAPIService;
import com.ctshk.rpc.hotel.service.IHotelService;
import com.ctshk.rpc.hotel.service.INCNBHotelService;
import com.ctshk.rpc.hotel.service.IWestMinisterHotelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 酒店资源 前端控制器
 * </p>
 *
 * @author yinhuan
 * @since 2021-03-03
 */
@RestController
@Api(value = "酒店管理", tags = "酒店管理")
@RequestMapping("/hotel")
public class HotelController extends BaseController {
    @DubboReference
    private IHotelService hotelService;
    @DubboReference
    private IChimeLongAPIService chimeLongAPIService;
    @DubboReference
    private INCNBHotelService ncnbHotelService;
    @DubboReference
    private IWestMinisterHotelService westMinisterHotelService;

    @ApiOperation(value="资源中心-酒店分页查询列表", notes="酒店分页查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "酒店分页查询列表", operDesc = "酒店分页查询列表")
    @PostMapping("/list")
    public Result<PageResponse<HotelListManagerDTO>> queryBusLineList(@RequestBody HotelListManagerReq hotelListQueryReq) {
        PageResponse<HotelListManagerDTO> response = hotelService.queyList(hotelListQueryReq);
        return Result.success(response);
    }

    @ApiOperation(value="修改酒店", notes="修改酒店")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改酒店", operDesc = "修改酒店")
    @PostMapping("/update")
    public Result updateHotel(@RequestBody @Valid HotelReq hotelReq) {
        TokenUser user = getCurrentUser(getRequest());
        return hotelService.updateHotel(hotelReq,user);
    }

    @ApiOperation(value = "查询酒店详情", notes = "查询酒店详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询酒店详情", operDesc = "查询酒店详情")
    @GetMapping(value = "/detail")
    public Result<HotelListDTO> queryDetail(@RequestParam(value = "id", required = true) Long id) {
        return Result.success(hotelService.queryDetail(id));
    }

    @ApiOperation(value="新增酒店", notes="新增酒店")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "新增酒店", operDesc = "新增酒店")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid HotelReq hotelReq){
        TokenUser user = getCurrentUser(getRequest());
        return hotelService.saveHotel(hotelReq,user);
    }

    @ApiOperation(value = "拉取长隆酒店", notes = "拉取长隆酒店")
    @PostMapping(value = "/save/api/chimelong/hotel")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "拉取长隆酒店", operDesc = "拉取长隆酒店")
    public Result saveAPIChimeLongHotel() {
        TokenUser user = getCurrentUser(getRequest());
        return chimeLongAPIService.saveAPIChimeLongHotel(user);
    }

    @ApiOperation(value = "根据产品代码拉取长隆酒店产品", notes = "根据产品代码拉取长隆酒店产品")
    @PostMapping(value = "/save/API/ChimeLong/HotelProduct")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "新增酒店", operDesc = "新增酒店")
    public Result saveAPIChimeLongHotelProduct(@RequestBody @Valid List<String> productCodes) {
        TokenUser user = getCurrentUser(getRequest());
        return chimeLongAPIService.getAPIChimeLongHotelProductByCode(productCodes,user);
    }

    @ApiOperation(value = "拉取龙腾捷旅酒店API", notes = "拉取龙腾捷旅酒店API")
    @PostMapping(value = "/save/api/ncnb/hotel")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "新增酒店", operDesc = "新增酒店")
    public Result saveApiNCNBHotel(@RequestBody @Valid HotelSearchReq req) {
        return ncnbHotelService.saveAPINCNBHotel(req,null, getCurrentUser(getRequest()), null, null, null, null, null);
    }

    @ApiOperation(value = "拉取西敏酒店API", notes = "拉取西敏酒店API")
    @PostMapping(value = "/save/api/westminister/hotel")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "新增酒店", operDesc = "新增酒店")
    public Result saveApiWestMinisterHotel(@RequestBody @Valid List<String> hotelCode) {
        TokenUser user = getCurrentUser(getRequest());
        return westMinisterHotelService.saveWestminsterHotel(user,hotelCode);
    }

    @ApiOperation(value = "拉取龙腾酒店房间", notes = "拉取龙腾酒店房间")
    @PostMapping(value = "/ncnb/getAllHotelRoomByCode")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "新增酒店", operDesc = "新增酒店")
    public Result getAllHotelRoomByCode(@RequestBody @Valid GetAllNCNBRoomByCodeReq getAllNCNBRoomByCodeReq) {
        TokenUser user = getCurrentUser(getRequest());
        return ncnbHotelService.saveAPINCNBHotelRoom(getAllNCNBRoomByCodeReq,user, null, null, null, null, null);
    }

    @ApiOperation(value = "更新龙腾地理信息数据", notes = "更新龙腾地理信息数据")
    @PostMapping(value = "/ncnb/updateNTStaticInfo")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "新增酒店", operDesc = "新增酒店")
    public Result updateNTStaticInfo(@RequestBody @Valid String actionName) {
        TokenUser user = getCurrentUser(getRequest());
        return ncnbHotelService.saveNTStaticInfo(actionName,user);
    }

    @ApiOperation(value = "龙腾酒店下单", notes = "龙腾酒店下单")
    @PostMapping(value = "/ncnb/createOrder")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增酒店", operDesc = "新增酒店")
    public Result createOrder(@RequestBody @Valid NCNBHotelCreateOrderReq req) {
        return ncnbHotelService.createOrder(req);
    }

    @ApiOperation(value = "长隆店下单", notes = "长隆店下单")
    @PostMapping(value = "/chimeLong/createOrder")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "新增酒店", operDesc = "新增酒店")
    public Result createOrder(@RequestBody @Valid ChimeLongCreateOrderPreDTO chimeLongCreateOrderPreDTO) {
        TokenUser user = getCurrentUser(getRequest());
        return chimeLongAPIService.chimeLongOrderCreate(chimeLongCreateOrderPreDTO,user);
    }

    @ApiOperation(value="长隆酒店订单修改", notes="长隆酒店订单修改")
    @OperationLogAnnotation(operModul = OperationLogModel.HOTEL, operType = OperationLogType.QUERY, operTitle = "长隆酒店订单修改", operDesc = "长隆酒店订单修改")
    @PostMapping("/chimelong/chimelongOrderUpdate")
    public Result<List<ChimeLongProxy>> chimelongOrderUpdate(@RequestBody ChimeLongOrderUpdateReq chimeLongOrderUpdateReq) {
        TokenUser user = getCurrentUser(getRequest());
        Result result = chimeLongAPIService.chimelongOrderUpdate(chimeLongOrderUpdateReq, user);
        return result;
    }

    @ApiOperation(value = "长隆酒店取消订单", notes = "长隆酒店取消订单")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "编辑时查询巴士路线详情", operDesc = "编辑时查询巴士路线详情")
    @GetMapping(value = "/chimeLong/cancelOrder")
    public Result cancelOrder(@RequestParam(value = "chimeLongIdOrOtaId", required = true) String chimeLongIdOrOtaId) {
        TokenUser user = getCurrentUser(getRequest());
        return chimeLongAPIService.chimeLongOrderCancel(chimeLongIdOrOtaId,user);
    }

    @ApiOperation(value="酒店房型資源列表查询", notes="酒店房型資源列表查询")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "代理商管理列表查询", operDesc = "代理商管理列表查询")
    @PostMapping("/queryAllHotelList")
    public Result<PageResponse<HotelQueryDTO>> queryAllHotelList(@RequestBody HotelQueryReq req){
        PageResponse<HotelQueryDTO> hotelQueryDTO = hotelService.queryAllHotelList(req);
        return Result.success(hotelQueryDTO);
    }

    @ApiOperation(value="龙腾酒店城市列表查询", notes="龙腾酒店城市列表查询")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "龙腾酒店城市列表查询", operDesc = "龙腾酒店城市列表查询")
    @GetMapping("/queryAllHotelList")
    public Result<List<CNHotelAreaDTO>> queryHotelCityList(){
        List<CNHotelAreaDTO> hotelCityDTOList =ncnbHotelService.queryHotelCityList();
        return Result.success(hotelCityDTOList);
    }

    @ApiOperation(value="龙腾酒店价格计划/价格库存查询", notes="龙腾价格计划/价格库存查询")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "龙腾酒店价格计划/价格库存查询", operDesc = "龙腾酒店价格计划/价格库存查询")
    @PostMapping("/queryRatePlanSearch")
    public Result<List<RatePlanSearchDTO>> queryRatePlanSearch(@RequestBody @Valid RatePlanSearchReq req){
        List<RatePlanSearchDTO> ratePlanSearchDTOList = ncnbHotelService.queryRatePlanSearch(req);
        return Result.success(ratePlanSearchDTOList);
    }

    @ApiOperation(value = "取消龙腾酒店下单", notes = "取消龙腾酒店下单")
    @GetMapping(value = "/ncnb/{orderId}")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改", operDesc = "取消酒店")
    public Result<BookingCheckDTO> bookingCancel(@PathVariable String orderId) {
        return ncnbHotelService.bookingCancel(orderId,getCurrentUser(getRequest()));
    }

    @ApiOperation(value="长隆酒店协议获取", notes="长隆酒店协议获取")
    @OperationLogAnnotation(operModul = OperationLogModel.HOTEL, operType = OperationLogType.QUERY, operTitle = "长隆酒店协议获取", operDesc = "长隆酒店协议获取")
    @PostMapping("/chimelong/chimeLongGetProtocal")
    public Result<List<ChimeLongProxy>> chimeLongGetProtocal(@RequestBody ChimelongProtocalReq chimelongProtocalReq) {
        TokenUser user = getCurrentUser(getRequest());
        Result result = chimeLongAPIService.chimeLongGetProtocal(chimelongProtocalReq, user);
        return result;
    }
}
